<?php

namespace  Ekadmin\Controller;
use \Think\Controller;
use Think\Page;

class QuyuController extends CommonController
{
        public  function index()
        {
            $where['uniacid'] = $this->uniacid;
            
            $obj = M('quyu');
            $count = $obj->where($where)->count();
            $list = $obj->where($where)->order('sort')->select();


            $this->assign('count',$count);
            $this->assign('list',$list);
            $this->display();
        }


        public function  edit()
        {

            $data = M('quyu')->where("id=".I("id")." and uniacid=".$this->uniacid)->find();
            $this->assign('data',$data);
            $this->display('form');
        }




        public function  add()
        {

            $this->display('form');
        }

        public function update()
        {
                if(IS_POST){
                    $param = I('post.');
                    if(!$param['name']){
                        ajax_return(1,'请填写线路名称');
                    }

                    $obj = M('quyu');
                     if($param['id']){
                            $obj->save($param);
                    }else{
                        
                        $map["uniacid"]=$this->uniacid;
                        $map["name"]=$param["name"];

                         if(M('quyu')->where($map)->find()){
                             ajax_return(1,'线路已存在');
                         }

                         $param['addtime']  = time();
                         $param['uniacid'] = $this->uniacid;
                            $obj->add($param);
                    }

                    ajax_return(0,'保存成功',U('index'));

                }
        }

        public function del()
        {
            if(IS_POST){
                $param = I('id');
                if(is_array($param)){

                }else{
                    $map['id'] = $param;
                }
                
                $map["uniacid"]=$this->uniacid;

                M('quyu')->where($map)->delete();

                ajax_return(0,'删除成功');
            }
        }






}